A micro controller is a processor on a microchip that performs, for example, arithmetic and logic operations. A micro controller creates one or more tasks, and each task performs a set of instructions. For example, one task may update an entry in a database.
In typical network processing applications, different tasks often access the same database. In some cases, there are multiple time critical tasks (referred to herein as “user tasks”) that need to access the database to read data. The time critical tasks may be, for example, tasks that perform packet processing. The term “packet” refers to a unit of data.
On the other hand, the data in the database may not be updated as often as it is read. Therefore, there may be one or a few non time-critical tasks that update the database from time to time (referred to herein as “update tasks”).
To avoid one task reading a database entry while another task is updating the same database entry, user and update tasks are not allowed to access the database in parallel. Currently, semaphore mechanisms may be used to allow one task at a time to access a database. A semaphore may be, for example, a bit that is set to a first pre-determined value to indicate that a task has “taken the semaphore” and is accessing the database. The bit may be set to a second pre-determined value to indicate that a task has “released the semaphore” and is no longer accessing the database.
Therefore, when a task wishes to access the database, the task checks the value of the semaphore. If the semaphore has not been taken by another task, the checking task updates the value of the semaphore to indicate that it is accessing the database (i.e., takes the semaphore). Once the task has completed its access, the task resets the value of the semaphore to indicate that it is no longer accessing the database (i.e., releases the semaphore). Thus, a task may check the value of the semaphore to determine whether another task is accessing the database.
Semaphore mechanisms are symmetric in the sense that both the task that is reading data (e.g., a user task) and the task that is updating the database share the overhead of semaphore maintenance. In particular, each type of task must check the value of the semaphore to determine whether another task is accessing the database, and, if the semaphore is available, the task must set the value of the semaphore to prevent other tasks from doing so, and reset the value of the semaphore to let other tasks use the semaphore to access the database.
Typically, there are multiple user tasks that need access to the database. When a task has taken the semaphore, the task prevents other tasks from accessing the database until the semaphore is released. This leads to poor performance for network processing applications.